<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>商品回购</title>
<link href="${basePath }/css/ui.css" rel="stylesheet" type="text/css">
<jsp:include page="/header.jsp"></jsp:include>
<script type="text/javascript">
	$(function() {
		$("input[type='radio']").click(function() {
			var type = $(this).val();
			$(".b_div").find("div").hide();
			if(type==1) $(".b_div").find("div").eq(0).show();
			else if(type==2) $(".b_div").find("div").eq(1).show();
		});
		
		initDialog();
		
	});
	
	function reCalc(input) {
		var wipeAmount = Number($(input).val());
		var sumPrice = Number($("input[name='sum_price']").val());
		$("input[name='cash_amount']").val(sumPrice.sub(wipeAmount));
		$("input[name='pay_amount']").val(sumPrice.sub(wipeAmount));
	}
	
	function confirm() {
		var payType = $("input[name='pay_type']:checked").val();
		$("#confirm_pay_dialog").find("span[name='cash_amount']").text($(".b_div").find("input[name='cash_amount']").val());
		$("#confirm_pay_dialog").find("span[name='wipe_amount']").text($(".b_div").find("input[name='wipe_amount']").val());
		$("#confirm_pay_dialog").find("span[name='bank_no']").text($(".b_div").find("input[name='bank_no']").val());
		$("#confirm_pay_dialog").find("span[name='account_name']").text($(".b_div").find("input[name='account_name']").val());
		$("#confirm_pay_dialog").find("span[name='bank_name']").text($(".b_div").find("input[name='bank_name']").val());
		$("#confirm_pay_dialog").find("div").hide();
		$("#div"+payType).show();
		$("#confirm_pay_dialog").dialog("open");
	}
	
	function initDialog() {
		$("#confirm_pay_dialog").dialog({
			title:"消费确认",
			autoOpen: false,
			height: 400,
			width: 300,
			modal: true,
			buttons:[{
				text:"确定",
				click:function() {
					var payType = $("input[name='pay_type']:checked").val();
					$.ajax({
						url:"${basePath}/buyback/buy.htm",
						type:"post",
						data:"pay_type="+payType+"&sum_price=${buyback_sumprice}&"+$("#form"+payType).serialize(),
						dataType:"json"
					}).done(function(data){
						$.jqalert(data.msg, "提示", function() {
							if(data.isSuccess) {
								$("#confirm_pay_dialog").dialog("close");
								window.location="${basePath}/buyback/index.htm";
							}
						});
					});
				}
			},{
				text:"取消",
				click:function() {
					$("#confirm_pay_dialog").dialog("close");
				}
			}]
		});
	}
</script>
</head>
<body>
	<div class="main">
        <div class="cont">
            <h2 class="title">结算信息：</h2>
            <div class="b_div">
            	<p class="clearfix">
					<span class="info_s fl">付款方式：
						<input type="radio" name="pay_type" value="1" checked="checked">现金&nbsp;
						<input type="radio" name="pay_type" value="2">银行转账
					</span>
				</p>
				<p class="clearfix">
					<span class="info_s fl">回收总金额：<input name="sum_price" type="text" readonly="readonly" value="${buyback_sumprice }">元</span>
				</p>
				<div>
					<form id="form1">
						<p class="clearfix">
							<span class="info_s fl">现金支付：<input name="cash_amount" type="text" value="${buyback_sumprice }">元</span>
						</p>
						<p class="clearfix">
							<span class="info_s fl">抹零：<input name="wipe_amount" type="text" value="0" onblur="reCalc(this);">元</span>
						</p>
						<input type="hidden" name="pay_amount" value="${buyback_sumprice }">
					</form>
				</div>
				<div style="display:none;">
					<form id="form2">
						<p class="clearfix">
							<span class="info_s fl">银行账号：<input type="text" name="bank_no" value="${buyback_customer.bank_no }"></span>
						</p>
						<p class="clearfix">
							<span class="info_s fl">户名：<input type="text" name="account_name" value="${buyback_customer.account_name }"></span>
						</p>
						<p class="clearfix">
							<span class="info_s fl">开户行：<input type="text" name="bank_name" value="${buyback_customer.bank_name }"></span>
						</p>
						<input type="hidden" name="pay_amount" value="${buyback_sumprice }">
					</form>
				</div>
			</div>
			
			<div class="text_c">
	        	<a href="javascript:;" class="yellow_btn btn" onclick="confirm();">确定</a>
	        	&nbsp;&nbsp;
	        	<a href="javascript:;" class="yellow_btn btn" onclick="reset();">重置</a>
	        </div>
		</div>
	</div>
	
	<div id="confirm_pay_dialog">
		<div id="div1">
			<table>
				<tr><th>付款方式：</th><td>现金支付</td></tr>
				<tr><th>回收总金额：</th><td>${buyback_sumprice }</td></tr>
				<tr><th>现金支付：</th><td><span name="cash_amount"></span>元</td></tr>
				<tr><th>抹零：</th><td><span name="wipe_amount"></span>元</td></tr>
				<tr><th>应付金额：</th><td>${buyback_sumprice }元</td></tr>
				<tr><th>实付金额：</th><td><span name="cash_amount"></span>元</td></tr>
			</table>
		</div>
		<div id="div2">
			<table>
				<tr><th>付款方式：</th><td>银行转账</td></tr>
				<tr><th>回收总金额：</th><td>${buyback_sumprice }</td></tr>
				<tr><th>银行账号：</th><td><span name="bank_no"></span></td></tr>
				<tr><th>户名：</th><td><span name="account_name"></span></td></tr>
				<tr><th>开户行：</th><td><span name="bank_name"></span></td></tr>
			</table>
		</div>
	</div>

</body>
</html>